package com.manage.system.web.controller;

import com.manage.common.core.result.JsonResult;
import com.manage.common.core.valid.AddGroup;
import com.manage.common.core.valid.UpdateGroup;
import com.manage.common.log.annotation.OperateLog;
import com.manage.common.log.enums.BusinessType;
import com.manage.common.permissions.annotation.HasPermissions;
import com.manage.system.api.request.dict.DictTypeAddOrEditParam;
import com.manage.system.api.request.dict.DictTypeQueryParam;
import com.manage.system.api.service.ISysDictTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zhangqing
 * @version V1.0
 * @description 字典类型控制层
 * @date 6/3/2021 12:49 PM
 */
@RestController
@RequestMapping("/dict-type")
@AllArgsConstructor
@Api(tags = "字典类型控制层", value = "SysDictTypeController")
public class SysDictTypeController {

    private final ISysDictTypeService sysDictTypeService;

    @ApiOperation("(分页)获取字典类型列表")
    @PostMapping(value = "/findDictTypeListPage")
    public JsonResult findDictTypeListPage(@RequestBody DictTypeQueryParam dictTypeQueryParam){
        return sysDictTypeService.findDictTypeListPage(dictTypeQueryParam);
    }

    @ApiOperation("批量删除字典类型")
    @DeleteMapping("/batchDelDictType")
    @HasPermissions("system:dict:remove")
    @OperateLog(module ="字典管理",title = "删除字典类型", businessType = BusinessType.DELETE)
    public JsonResult batchDelDictType(@RequestBody List<Long> dictTypeIds) {
        return sysDictTypeService.batchDelDictType(dictTypeIds);
    }

    @ApiOperation("添加字典类型")
    @PostMapping("/addDictType")
    @HasPermissions("system:dict:add")
    @OperateLog(module ="字典管理",title = "添加字典类型", businessType = BusinessType.INSERT)
    public JsonResult addDictType(@Validated({AddGroup.class}) @RequestBody DictTypeAddOrEditParam dictTypeAddOrEditParam) {
        return sysDictTypeService.addDictType(dictTypeAddOrEditParam);
    }

    @ApiOperation("编辑字典类型")
    @PutMapping("/editDictType")
    @HasPermissions("system:dict:edit")
    @OperateLog(module ="字典管理",title = "修改字典类型", businessType = BusinessType.UPDATE)
    public JsonResult editDictType(@Validated({UpdateGroup.class}) @RequestBody DictTypeAddOrEditParam dictTypeAddOrEditParam) {
        return sysDictTypeService.editDictType(dictTypeAddOrEditParam);
    }
}
